package banking.reports;

// 修改 Bank 类的导入路径以使用 day8 版本
import day8.Bank;
// 修改 Customer、Account、SavingAccount和CheckingAccount类的导入路径
import day8.Customer;
import day8.Account;
import day8.SavingAccount;
import day8.CheckingAccount;

public class CustomerReport {
    public void generateReport() {
        Bank bank = Bank.getBanking(); // 检索单例银行对象
        
        System.out.println("**CUSTOMERS REPORT**");
        System.out.println("=================="); // 修改标题格式
        
        for (int i = 0; i < bank.getNumOfCustomers(); i++) {
            Customer customer = bank.getCustomer(i);
            System.out.printf("Customer: %s, %s%n", customer.getLastName(), customer.getFirstName());
            
            // 分别处理 SavingsAccount 和 CheckingAccount，确保顺序正确
            for (int j = 0; j < customer.getNumOfAccounts(); j++) {
                Account account = customer.getAccount(j);
                if (account instanceof SavingAccount) {
                    System.out.printf("    Savings Account: current balance is $%,.2f%n", account.getBalance());
                }
            }
            for (int j = 0; j < customer.getNumOfAccounts(); j++) {
                Account account = customer.getAccount(j);
                if (account instanceof CheckingAccount) {
                    System.out.printf("    Checking Account: current balance is $%,.2f%n", account.getBalance()); // 修正账户类型名称拼写
                }
            }
            
            // 每个客户信息之间添加四个空行
            if (i < bank.getNumOfCustomers() - 1) {
                System.out.println(); // 修改为一个空行
            }
        }
    }
}
